def update_direction(curr_direction, diff):
    output = 0
    if curr_direction == 1 and diff[0] == -1:
        curr_direction = -1
        output = 4
        return curr_direction, output
    elif curr_direction == 2 and diff[1] == -1:
        curr_direction = -2
        output = 4
        return curr_direction, output
    elif curr_direction == -1 and diff[0] == 1:
        curr_direction = 1
        output = 4
        return curr_direction, output
    elif curr_direction == -2 and diff[1] == 1:
        curr_direction = 2
        output = 4
        return curr_direction, output
        
        
    elif curr_direction == 1 and diff[0] == 1:
        curr_direction = 1
        output = 3
        return curr_direction, output
    elif curr_direction == 2 and diff[1] == 1:
        curr_direction = 2
        output = 3
        return curr_direction, output
    elif curr_direction == -1 and diff[0] == -1:
        curr_direction = -1
        output = 3
        return curr_direction, output
    elif curr_direction == -2 and diff[1] == -1:
        curr_direction = -2
        output = 3
        return curr_direction, output

    elif curr_direction == 1 and diff[1] == 1:
        curr_direction = 2
        output = 2
        return curr_direction, output
    elif curr_direction == 2 and diff[0] == -1:
        curr_direction = -1
        output = 2
        return curr_direction, output
    elif curr_direction == -1 and diff[1] == -1:
        curr_direction = -2
        output = 2
        return curr_direction, output
    elif curr_direction == -2 and diff[0] == 1:
        curr_direction = 1
        output = 2
        return curr_direction, output

    elif curr_direction == 1 and diff[1] == -1:
        curr_direction = -2
        output = 1
        return curr_direction, output
    elif curr_direction == 2 and diff[0] == 1:
        curr_direction = 1
        output = 1
        return curr_direction, output
    elif curr_direction == -1 and diff[1] == 1:
        curr_direction = 2
        output = 1
        return curr_direction, output
    elif curr_direction == -2 and diff[0] == -1:
        curr_direction = -1
        output = 1
        return curr_direction, output

    else:
        return curr_direction, output

# 初始化

def CalcDir(coordinates):
    curr_direction = 2#初始化小车朝向
    outputs = []
    # 遍历每个坐标，并更新面朝的方向
    for i in range(len(coordinates) - 1):
        diff = (coordinates[i+1][0] - coordinates[i][0], coordinates[i+1][1] - coordinates[i][1])
        curr_direction, a = update_direction(curr_direction, diff)
        outputs.append(a)
        if i ==len(coordinates)-2:
            outputs.append(0x41)
    return outputs
    # 打印结果
    #print(outputs)
